//全局设置axios
axios.defaults.baseURL='http://192.168.5.184:2030/apis';
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8';
Vue.prototype.$http = axios;
var PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuEzENS7csnq1iceqi1obPZbuoL6q9gJxzVw7NlGOXjqK295qFawem2B7N6nZHsQOyp6xXl6x2ni7hjjUs08cxp23TPpBC+olYx7P49cvhg5c0xQJ09NN4UddeKPUZZUBCh2FYb9qiF9q9ic7+Wd+ba/dQoryQGSVs93aeVqnlFLQgfUkiNnS/ZXYr248djt5WEDaZ39dGnBQOKllptHs+TrbdISEaqlVBD8GocVGNXYZu1WbeIjWXAlZcXmgtx+OCuGXfi76ERcWANOKkzWilYuULBvwn7E7nzi0C8eL30/6ieWDd6F7cenpPMfRgkhexjukosqabwMHlkOJkeZYZQIDAQAB";

//解析url参数函数
function parseParamObj(url) {
    let paramsStr = url.substring(url.indexOf("?")+1); //typeId=27
    let paramsArray = paramsStr.split("&"); //typeId=27 xxx=xxx
    let paramObj = {};
    $.each(paramsArray,function(index,param){
        let parmName = param.split("=")[0];
        let parmValue = param.split("=")[1];
        paramObj[parmName] = parmValue;
    })
    return paramObj;
}

function RsA_encryption(jsonData){
    var encrypt = new JSEncrypt();
    encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----\n'+ PUBLIC_KEY + '\n-----END PUBLIC KEY-----');
    return encrypt.encryptLong(JSON.stringify(jsonData));
}

/*
  axios的前置请求拦截器
*/
axios.interceptors.request.use(config=>{
        // console.log(config)
        if (localStorage.getItem("shareUrl")){
            config.headers.TOKEN = localStorage.getItem("shareUrl");
        }
        return config;
    },
    error => {
        return Promise.reject(error);
    })
/*
  axios的响应请求拦截器
    config:就是当前的响应对象
*/
axios.interceptors.response.use(config=>{
        if (!(config.data.success) && config.data.msg === "void"){//同时让success和data作为判断条件
            location.href = "test.html";
        }
        return config;
    },
    error => {
        return Promise.reject(error);
    })

